unit EkParcaListeKistaslari;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClassEmptyList, Menus, DB, ADODB, ImgList, XPMan, StdActns,
  ActnList, StdCtrls, Buttons, fcLabel, Grids, Wwdbigrd, Wwdbgrid,
  ExtCtrls, fcStatusBar, wwdblook, Mask, wwdbedit, Wwdotdot, siComp,
  siLngLnk;

type
  TfmEkParcaListeKistaslari = class(TfmFormClassEmptyList)
    Temsilci: TwwDBLookupCombo;
    EkParcaAktarimQ: TADOQuery;
    EkParca: TwwDBLookupCombo;
    CarKod: TwwDBComboDlg;
    StokKoduk: TwwDBComboDlg;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure CarKodExit(Sender: TObject);
    procedure StokKodukExit(Sender: TObject);
    procedure aqEntryBeforePost(DataSet: TDataSet);
    procedure grdListeKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmEkParcaListeKistaslari: TfmEkParcaListeKistaslari;

implementation
uses data, UnitGenel, ana1;
{$R *.dfm}

procedure TfmEkParcaListeKistaslari.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmEkParcaListeKistaslari := nil;
end;

procedure TfmEkParcaListeKistaslari.FormShow(Sender: TObject);
begin
  inherited;
  if not dm.spCaYetkili.Active then
    dm.spCaYetkili.open;

  EkParcaAktarimQ.Close;
  EkParcaAktarimQ.Open;

  aqEntry.Close;
  aqEntry.Open;
end;

procedure TfmEkParcaListeKistaslari.CarKodExit(Sender: TObject);
var
  Bilgi: string;
  CariKod: integer;
  Carikodu: string[25];
begin
  if (Sender as twwdbcombodlg).ReadOnly = True then
    exit;

  Bilgi := CariBul(Sender);

  if Bilgi = '' then
    exit;

  if (not (dm.spFatura.State in [dsinsert, dsEdit])) then
    aqEntry.Edit;

  if Bilgi <> '0' then
  begin
    Carikod := Strtoint(Copy(Bilgi, 1, Pos(',', Bilgi) - 1));
    Delete(Bilgi, 1, Pos(',', Bilgi));
    Carikodu := Copy(Bilgi, 1, Pos(',', Bilgi) - 1);

    aqEntry.FieldByName('carikod').value := CariKod;
    aqEntry.FieldByName('carikodu').value := CariKodu;
  end
  else
  begin
    aqEntry.FieldByName('carikod').value := Null;
    aqEntry.FieldByName('carikodu').value := Null;
    Carkod.text := '';
  end;
end;


procedure TfmEkParcaListeKistaslari.StokKodukExit(Sender: TObject);
var
  Bilgi, Stokkodu: string;
  StokKod: integer;
begin
  Bilgi := StokBul(Sender, 0, 'C');

  if Bilgi = '' then
    exit;

  if (not (dm.spFatura.State in [dsinsert, dsEdit])) then
    aqEntry.Edit;

  if Bilgi <> '0' then
  begin
    Stokkod := Strtoint(Copy(Bilgi, 1, Pos(',', Bilgi) - 1));
    Delete(Bilgi, 1, Pos(',', Bilgi));
    Stokkodu := Copy(Bilgi, 1, Pos(',', Bilgi) - 1);

    aqEntry.FieldByName('stokkod').Value := Stokkod;
    aqEntry.FieldByName('stokkodu').Value := Stokkodu;
  end
  else
  begin
    aqEntry.FieldByName('stokkod').Value := null;
    aqEntry.FieldByName('stokkodu').Value := null;
  end;
end;

procedure TfmEkParcaListeKistaslari.aqEntryBeforePost(DataSet: TDataSet);
begin
  inherited;
  if DataSet.FieldByName('Sec').IsNull then
    DataSet.FieldByName('Sec').Value := False;

  if DataSet.FieldByName('Aktif').IsNull then
    DataSet.FieldByName('Aktif').Value := False;
end;

procedure TfmEkParcaListeKistaslari.grdListeKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
  if Key = '@' then
    Key := #0;
end;

end.

